/**
 * 
 */
package net.fdukedom.epicurus.domain.entity;

/**
 * Message type class.
 * @author Sergey Vishnyakov
 *
 */
public final class MessageType {

    /**
     * Message type id.
     */
    private int id;

    /**
     * Message type name.
     */
    private String  name;

    /**
     * Related plugin.
     */
    private Plugin plugin;

    /**
     * Default constructor.
     */
    public MessageType() {
    }

    /**
     * Creates instance out of all required data.
     *
     * @param name message name
     * @param plugin message's plugin
     */
    public MessageType(String name, Plugin plugin) {
        this.name = name;
        setPlugin(plugin);
    }

    /**
     * Retrurns id.
     *
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * Sets id.
     *
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Returns name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets name.
     *
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns plugin.
     *
     * @return the plugin
     */
    public Plugin getPlugin() {
        return plugin;
    }

    /**
     * Sets plugin.
     * 
     * @param plugin the plugin to set
     */
    public void setPlugin(Plugin plugin) {
        this.plugin = plugin;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final MessageType that = (MessageType) o;

        if (name != null ? !name.equals(that.name) : that.name != null) return false;

        return true;
    }

    public int hashCode() {
        return (name != null ? name.hashCode() : 0);
    }

    public String toString() {
        StringBuilder text = new StringBuilder();
        text.append("{id: ");
        text.append(id);
        text.append(", name: ");
        text.append(name);
        text.append(", plugin name: ");
        text.append(plugin.getName());
        text.append("}");
        return text.toString();
    }
}
